import Vue from 'vue'
import App from './App'
import navBar from '@/components/m-navBar.vue'
import userBar from '@/components/m-userBar.vue'
import mBottom from '@/components/m-bottom.vue'
import mNodata from '@/components/m-noData.vue'
import $mConfig from "./config/index.config.js"
import store from './store/index.js'
import $routesConfig from './config/routes.config.js'
import $router from './common/router.js'
import $util from './common/util.js'
import * as $apis from 'apis/index.js'

Vue.prototype.$mConfig = $mConfig;
Vue.prototype.$apis=$apis
Vue.prototype.$util=$util
Vue.prototype.$router=$router
Vue.prototype.$routesConfig=$routesConfig
Vue.config.productionTip = false
Vue.component("navBar",navBar)
Vue.component("userBar",userBar)
Vue.component("mBottom",mBottom)
Vue.component("mNodata",mNodata)

App.mpType = 'app'

const app = new Vue({
    ...App,
	store
})
app.$mount()
$router.beforeEach((navType,to)=>{ // 这里是路由接收的地方，可以在这里处理路由请求
	if(to.route.requireAuth){ //需要登录权限验证的路由
		if(store.state.token===''){ //未登录
			uni.redirectTo({
				url: $util.objParseUrlAndParam($routesConfig.login.path)
			})
		}else{
			uni[navType]({
				url:$util.objParseUrlAndParam(to.route.path,to.query)
			})
		}

	}else{
		uni[navType]({
			url:$util.objParseUrlAndParam(to.route.path,to.query)
		})
	}
})
